@extends('backend.layouts.app')

@section('content')
<div class="layui-card">
    <div class="layui-card-header layui-card-header-auto">
        更新用户信息
    </div>
    <div class="layui-card-body">
        <form class="layui-form">
            <div class="layui-row">
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="username" lay-verify="required"
                                value="{{auth('manager')->user()->username}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">姓名</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="name" lay-verify="required"
                                value="{{auth('manager')->user()->name}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="name" class="layui-form-label">性别</label>
                        <div class="layui-input-block">
                            <select name="sex" lay-verify="required">
                                <option value="0" @if(auth('manager')->user()->sex == 0)selected @endif>女</option>
                                <option value="1" @if(auth('manager')->user()->sex == 1)selected @endif>男</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item">
                        <label for="mobile" class="layui-form-label">手机</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="mobile" lay-verify="required|phone"
                                value="{{auth('manager')->user()->mobile}}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="email" class="layui-form-label">邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="email" lay-verify="required|email"
                                value="{{auth('manager')->user()->email}}">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="description" class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="description"
                        class="layui-textarea">{{auth('manager')->user()->description??''}}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" onclick="make()">确 认</button>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection
@section('script')
<script type="text/javascript">
    function make() {
        $.ajax({
            url: "{{route('admin.auth.manager.update',['manager_id'=>auth('manager')->user()->manager_id])}}",
            type: 'post',
            data: $.param({
                _method: 'put',
                _token:'{{csrf_token()}}'
            }) + '&' + $('form').serialize(),
            success: function success(data) {
                alert(data.message)
                if (data.status){
                    window.location.reload('/')
                }
            }
        });
    }
</script>
@endsection
